unit ufrmChoiceDate;

interface

uses
  SysUtils, Classes, Controls, Forms,
  cxTextEdit,
  cxDropDownEdit, ExtCtrls, Calendar, StdCtrls,
  cxSpinButton, cxButtons,
  Buttons, Menus, cxLookAndFeelPainters, cxSpinEdit,
  cxControls, cxContainer, cxEdit, cxMaskEdit, Grids, cxGraphics;

type
  TfrmChoiceDate = class(TForm)
    cal1: TCalendar;
    pnl1: TPanel;
    cbbMonth: TcxComboBox;
    lbl1: TLabel;
    cedtYear: TcxTextEdit;
    lbl2: TLabel;
    cxSpinButton1: TcxSpinButton;
    cbtnPrew: TcxButton;
    cbtnNext: TcxButton;
    lbl3: TLabel;
    edtDate: TEdit;
    btnOK: TBitBtn;
    cbtnToday: TcxButton;
    procedure cbbMonthPropertiesChange(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure cedtYearPropertiesChange(Sender: TObject);
    procedure cbbMonthPropertiesCloseUp(Sender: TObject);
    procedure cal1Change(Sender: TObject);
    procedure cbtnPrewClick(Sender: TObject);
    procedure cbtnNextClick(Sender: TObject);
    procedure cal1DblClick(Sender: TObject);
    procedure cbtnTodayClick(Sender: TObject);
  private
    procedure SetDate(const Value: string);
    function GetDate: string;
    { Private declarations }
  public
    { Public declarations }
    //property Date: TDate read FDate write SetDate;
    property DateStr: string read GetDate write SetDate;
  end;

var
  frmChoiceDate: TfrmChoiceDate;

implementation

{$R *.dfm}

procedure TfrmChoiceDate.cbbMonthPropertiesChange(Sender: TObject);
begin
  cal1.Month := cbbMonth.ItemIndex + 1;
end;

procedure TfrmChoiceDate.FormCreate(Sender: TObject);
begin
//  cedtYear.Text := IntToStr(cal1.Year);
//  cbbMonth.ItemIndex := cal1.Month - 1;
end;

procedure TfrmChoiceDate.cedtYearPropertiesChange(Sender: TObject);
begin
  cal1.Year := StrToInt(cedtYear.Text);
end;

procedure TfrmChoiceDate.cbbMonthPropertiesCloseUp(Sender: TObject);
begin
  cal1.SetFocus;
end;

procedure TfrmChoiceDate.cal1Change(Sender: TObject);
begin
  cedtYear.Text := IntToStr(cal1.Year);
  cbbMonth.ItemIndex := cal1.Month - 1;
  edtDate.Text := FormatDateTime('YYYY-MM-DD', EncodeDate(cal1.Year, cal1.Month, cal1.Day));
end;

procedure TfrmChoiceDate.cbtnPrewClick(Sender: TObject);
begin
  cal1.PrevMonth;
end;

procedure TfrmChoiceDate.cbtnNextClick(Sender: TObject);
begin
  cal1.NextMonth;
  cal1.UpdateCalendar
end;

procedure TfrmChoiceDate.cal1DblClick(Sender: TObject);
begin
  ModalResult := mrOk;
end;

procedure TfrmChoiceDate.SetDate(const Value: string);
begin
  cal1.CalendarDate := StrToDateDef(Value, Now);
end;

function TfrmChoiceDate.GetDate: string;
begin
  Result := edtDate.Text;
end;

procedure TfrmChoiceDate.cbtnTodayClick(Sender: TObject);
begin
  cal1.CalendarDate := Now;
end;

end.
